import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import axios from "axios";

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    redirect:'/index',
    children:[
      {path: '/user', component: () => import('../views/user/UserView.vue')},
      {path: '/index', component: () => import('../views/IndexView.vue')},
      {path: '/scenic', component: () => import('../views/scenic/ScenicView.vue')},
      {path: '/personalData', component: () => import('../views/user/PersonalData.vue')},
      {path: '/strategy', component: () => import('../views/comment/StrategyView.vue')},
      {path: '/comment', component: () => import('../views/comment/Comment.vue')},
    ]
  },
  {path: '/login', component: () => import('../views/LoginView')},

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
/*//src/router/index.js
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token');
  if (to.path !== '/login' && !token) {
    next('/login');
  } else {
    next();
  }
});

//响应拦截器处理 Token 过期
axios.interceptors.response.use(
    response => response,
    error => {
      if (error.response.status === 401) {
        localStorage.removeItem('token');
        router.push('/login');
      }
      return Promise.reject(error);
    }
);*/
export default router